
<?php include './application/views/top.php'; ?>
<script src="/static/js/gsdai.js"></script>
<script src="/static/js/ajaxfileupload.js"></script>
<script src="/static/js/My97DatePicker/WdatePicker.js"></script>
<script src="/static/js/formCheck.js"></script>

<div class="clear"></div>
<div class="user_bottom all"></div>
<div class="clear h50"></div>
<div class="layout uc">
	<?php include './application/views/user/left.php'; ?>
	<div class="right">
		<div class="menu_list"><?php include './application/views/user/menu.php'; ?></div>
		<div class="clear h30"></div>
        <div class="fr">
		<input type="button" class="p_button" value="删除" onclick="del();"/>
		<input type="button" class="p_button" value="标记已读" onclick="read(1);"/>
		<input type="button" class="p_button" value="标记未读" onclick="read(0);"/>
        </div>
		<div class="clear"></div>
        <div class="cont">
			<form id="message_form">
			<input type="hidden" name="is_receive" value="1">
			<input type="hidden" id="status" name="status" value="1">
        	<ul class="tbt">
            	<li class="w80"><input type="checkbox" id="select_all" onclick="selectAll(this);"/></li>
                <li class="w470">标题</li>
                <li class="w200">发件人</li>
                <li class="w168 npr">发送时间</li>
			</ul>
            <?php foreach ($list as $val){ ?>
        	<ul class="tbc">
            	<li class="w80"><input type="checkbox" name="id[]" value="<?php echo $val['id'];?>" /></li>
                <li class="w470"><span id="span_<?php echo $val['id'];?>" style="cursor: pointer;<?php if($val['fstatus']==0){echo "font-weight: bold;";}?>" onclick="view('<?php echo $val['id'];?>');"><?php echo $val['name'];?></span></li>
            	<li class="w200"><?php echo $val['sent_username'] ? $val['sent_username'] : 'admin';?></li>
            	<li class="w168 npr"><?php echo date('Y-m-d H:i',$val['add_time']);?></li>
			</ul>
            <?php }?>
            </form>
        </div>
        <div class="clear h30"></div>
        <div class="page">
            <div class="pagination">
            <?php echo $this->pagination->create_links();?>
            </div>
        </div>
	</div>
</div>
<div class="clear h50"></div>
<?php include "./application/views/footer.php";?>
<script>
function view(id){
	window.location='/message/view/'+id+'.html';
}

function del(){
	var options = {
		url : '/message/dodel',
		//clearForm :true,
		//resetForm :true,
		beforeSubmit:  checkForm,
		dataType: "json",
		type:"post",
		success : function(ret) {
			if(ret.msg==''){
				$('#dialog').dialog({
					modal:true,
					title:'系统提示',
					buttons:{"确定":function(){$(this).dialog("close");}},
					close: function() {
						//location=ret.data.url;
						if(ret.data.url==''){
							window.location.reload();
						}else{
							window.location=ret.data.url;
						}
					}
				}); 
				$("#msg").html("操作成功");
			}else{
				$('#dialog').dialog({
					modal:true,
					title:'系统提示',
					buttons:{"确定":function(){$(this).dialog("close");}},
					close: function() {
						$("#message_form").resetForm();
					}
				}); 
				$("#msg").html(ret.msg);
			}
		}
	};
	$("#message_form").ajaxSubmit(options);
	return false;
}

function read(status){
	$("#status").val(status);
	var options = {
		url : '/message/doread',
		beforeSubmit:  checkForm,
		dataType: "json",
		type:"post",
		success : function(ret) {
			if(ret.msg==''){
				$('#dialog').dialog({
					modal:true,
					title:'系统提示',
					buttons:{"确定":function(){$(this).dialog("close");}},
					close: function() {
						//location=ret.data.url;
						if(ret.data.url==''){
							window.location.reload();
						}else{
							window.location=ret.data.url;
						}
					}
				}); 
				$("#msg").html("操作成功");
			}else{
				$('#dialog').dialog({
					modal:true,
					title:'系统提示',
					buttons:{"确定":function(){$(this).dialog("close");}},
					close: function() {
						$("#message_form").resetForm();
					}
				}); 
				$("#msg").html(ret.msg);
			}
		}
	};
	$("#message_form").ajaxSubmit(options);
	return false;
}

function checkForm(){
	var form = document.getElementById("message_form");
	var g = false;
	for (var i=1;i<form.elements.length;i++)    {
		if(form.elements[i].type=="checkbox"){ 
            e=form.elements[i]; 
            if(e.checked==true){
				g = true;
            }
        } 
	}
	if(g==false){
		$('#dialog').dialog({
			modal:true, //蒙层（弹出会影响页面大小）
			title:'系统提示',
			buttons:{"确定":function(){$(this).dialog("close");}}
		}); 
		$("#msg").html("请先选择");
		return false;
	}else{
		$('#dialog').dialog({
			modal:true, //蒙层（弹出会影响页面大小）
			title:'系统提示'
		}); 
		$("#msg").html("处理中...");
		return true;
	}
}

function selectAll(obj){
	var form = document.getElementById("message_form");
	if(obj.checked==true){
		for (var i=1;i<form.elements.length;i++)    {
			if(form.elements[i].type=="checkbox"){ 
	            e=form.elements[i]; 
	            e.checked=true; 
	        } 
		}
	}else{
		for (var i=1;i<form.elements.length;i++)    {
			if(form.elements[i].type=="checkbox"){ 
	            e=form.elements[i]; 
	            e.checked=false; 
	        } 
		}
	}
}
</script>